layui.use(["table",'form',"util","layer"],function () {
    var table = layui.table;
    var util = layui.util;
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.jquery;

    var jobid= $("#jobtitlessId").val(); //传入的字典大类id.
    //
    var showdictTable = function() {
        table.render({
              elem: '#jjl_job'
            , height: 350
            , url: '/manageA/jjl_bydpid?typeId='+jobid //数据接口
            , cols: [[ //表头
                {field: 'id', title: 'ID',width:'20%'}
                , {field: 'job', title: '部门职位',width:'40%'}
                , {title: '操作',width:'40%',toolbar:"#barDemo"}
            ]]
        });
    };
    showdictTable();
    //触发事件(添加字典大类)
    $("#jjlbut").click(function () {
        //保存字典大类。
        var type  = $("#type").val();

        var data = {
            job:type,

            dp_id:jobid
        }

        $.post("/manageA/jjl_tianjiajob",data,function (bo) {
            $.ajaxSettings.async = false;
            if (bo) {
                parent.layer.msg("新增成功!", {
                    time: 1000
                }, function() {
                    //重新加载父页面
                    parent.location.reload();
                });
            } else {
                layer.msg("添加失败",{
                    time:3000
                });
            }

            layer.close(index);

            $.ajaxSettings.async = true;
        })
    });
    table.on('tool(dictSubTable)', function (obj) {
        var data = obj.data; //当前行的数据。对象类型。
        if (obj.event === 'del') {
            layer.confirm('真的要删除此职位吗？', function (index) {
                var id = data.id
                var res= false
             $.post("/manageA/jjl_delbyidjob","jobid="+id,function (data1) {
                 if (data1) {
                     layer.msg("删除成功",{
                         time:3000,


                     });
                     window.location.reload();
                 } else {
                     layer.msg("删除失败",{
                         time:3000
                     });
                 }

             })
            });
        }
    });
});



